package com.hxw.schema.singleton;

/**
 * 双重校验锁
 * 在多线程环境下支持高性能
 * Created by wenx on 2020-02-15 13:45
 */
public class SingletonDemo2 {

    private static volatile SingletonDemo2 singletonDemo;

    private SingletonDemo2() {
    }

    public static SingletonDemo2 getInstance() {
        if(singletonDemo == null) {
            synchronized(SingletonDemo2.class){
                if(singletonDemo == null) {
                    singletonDemo = new SingletonDemo2();
                }
            }
        }
        return singletonDemo;
    }

    private void hello(){
        System.out.println("hello singleton demo2");
    }

    public static void main(String[] args) {
        SingletonDemo2 instance = SingletonDemo2.getInstance();
        instance.hello();
    }

}